IFs and LOOPs

We need to look at the code that compilers generate for high-level constructs like IF and WHILE

Let's start with the IF statement and see what actually happens

        if (x < y) {
            STUFF
        }
      
        bnlt x y end
        whatever code is generated by STUFF
end:
      
        bge x y end
        whatever code is generated by STUFF
end:
      

Let's double-check to make sure that this really does the right thing

What if the IF has an ELSE??

        if (x < y) {
            SOMESTUFF
        }
        else {
            OTHERSTUFF
        }
      
        bge x y else
        whatever code is generated by SOMESTUFF
else:   whatever code is generated by OTHERSTUFF
      
        bge x y else
        whatever code is generated by SOMESTUFF
        j end
else:   whatever code is generated by OTHERSTUFF
end:
      

Let's double-check to make sure that this really does the right thing

What about WHILE loops?

        while (x < y) {
            STUFF
        }
      
lp:     bge x y end
        whatever code is generated by STUFF
        j lp
end:
      

Let's double-check to make sure that this really does the right thing